/**
 * Created by Administrator on 2017/3/21.
 */
import React, { Component,Fragment } from 'react';
import {Form, Input, DatePicker, Select, InputNumber, Button, Tooltip, Icon, Alert, Upload} from 'antd';
import { connect } from 'dva';
import moment from 'moment';
import request from '@/utils/request';
import find from 'lodash/find';

const FormItem = Form.Item;
const Option = Select.Option;
let uuid = 10;

class AddPoliciesForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      fileList:[]
    };
  }


  render() {
    const formItemLayoutWithLabel = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
    };

    const { getFieldDecorator } = this.props.form;
    const props = {
      onRemove: (file) => {
        this.setState(({ fileList }) => {
          const index = fileList.indexOf(file);
          const newFileList = fileList.slice();
          newFileList.splice(index, 1);
          return {
            fileList: newFileList,
          };
        });
      },
      beforeUpload: (file) => {
        this.setState(({ fileList }) => ({
          fileList: [file],
        }));
        return false;
      },
      fileList: this.state.fileList,
      accept:'.bin'
    };
    return (
      <div>
        <Form>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               版本
            </span>
            )}
          >
            {getFieldDecorator('version', {
              initialValue: this.props.editRecord?this.props.editRecord.version:'',
              rules: [{ required: true, message: '请输入集中器号码' }],
            })(
              <Input />
            )}
          </FormItem>
          {
            !this.props.editRecord&&
            <FormItem
              {...formItemLayoutWithLabel}
              label={(
                <span>
               固件文件
            </span>
              )}
            >
              {getFieldDecorator('file', {
                rules: [{ required: true, message: '请选择固件文件' }],
              })(
                <Upload.Dragger {...props}>
                  <p className="ant-upload-text">点击选择固件文件</p>
                </Upload.Dragger>
              )}

            </FormItem>
          }

          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               每包大小(字节)
            </span>
            )}
          >
            {getFieldDecorator('per_package_size', {
              initialValue: this.props.editRecord?this.props.editRecord.per_package_size:256,
              rules: [{ required: true, message: '请输入每包大小(字节)' }],
            })(
              <InputNumber style={{width:'100%'}} />
            )}
          </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               备注
            </span>
            )}
          >
            {getFieldDecorator('remark', {
              initialValue: this.props.editRecord?this.props.editRecord.remark:'',
            })(
              <Input />
            )}
          </FormItem>
        </Form>


      </div>

    );
  }
}

const AddPoliciesFormWrap = Form.create()(AddPoliciesForm);
export default connect()(AddPoliciesFormWrap);


